package com.ruoyi.prodata.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.material.service.IMateriaPurchaseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 12605
 */
@RestController
@RequestMapping("/prodata/procurementStatistics")
public class ProcurementStatisticsController extends BaseController {
    @Autowired
    private IMateriaPurchaseRecordService materiaPurchaseRecordService;

    @GetMapping("/list")
    public AjaxResult list(Long projectId){
        List<Map<String, Object>> list = materiaPurchaseRecordService.selectProcurementByProjectId(projectId);
        HashMap<Object, Object> map = new HashMap<>();
        ArrayList<Object> nameList = new ArrayList<>();
        ArrayList<Object> rateList = new ArrayList<>();
        for (Map<String, Object> m : list) {
            nameList.add(Convert.toStr(m.get("name")));
            rateList.add(Convert.toStr(m.get("rate")));
        }
        map.put("nameList",nameList);
        map.put("rateList",rateList);
        return success(map);
    }
}
